/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package web.usuarios;

import Persistencia.*;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import controladores.*;
import dominio.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Alith
 */
public class ControladorSimpleModInforme extends SimpleFormController{

    ControladorInforme controlador;
    ControladorSesion controladorSes;
    InformeDomain obj;
    Informe objInfo;
    String idFisio="";

    @Override
    public ModelAndView onSubmit(Object command) throws ServletException{
        controlador = new ControladorInforme();
        obj=(InformeDomain) command;
        controlador.setInformeD(obj);
        objInfo=controlador.setInforme();
        controlador.setInformeMod();
        controlador.modificarInforme();
        Map<String, Object> myModel = new HashMap<String, Object>();
        myModel.put("id_fisio",objInfo.getSesion().getFisioterapeuta().getIdFisioterapeuta());
        myModel.put("informes", controlador.encontrarMisInformes(""+objInfo.getSesion().getFisioterapeuta().getIdFisioterapeuta()));
        return new ModelAndView("administrarInformes", "model", myModel);
    }

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        controlador = new ControladorInforme();
        idFisio=request.getParameter("id_fisio");
        Informe log = controlador.encontrarInforme(request.getParameter("id_informe"));
        InformeDomain logD=controlador.convertirDomain(log);
        return logD;
    }

    public void setControladorInforme(ControladorInforme productManager) {
        this.controlador = productManager;
    }

    public ControladorInforme getControladorInforme() {
        return controlador;
    }

    @SuppressWarnings("unchecked")
    protected Map referenceData(HttpServletRequest request) throws Exception {
        controladorSes=new ControladorSesion();
        Map referenceData = new HashMap();
        Informe log = controlador.encontrarInforme(request.getParameter("id_informe"));
        InformeDomain logD=controlador.convertirDomain(log);
        List<Sesion> list=new ArrayList();
        list.add(controladorSes.encontrarSesion(logD.getIdSesion()));
        if(request.getParameter("id_fisio")!=null){
            referenceData.put("listSesion", list);
        }
        return referenceData;
    }
}
